import React from "react";

/**
 * 公共基础组件
 */
class BaseComponent<P = {}, S = {}> extends React.PureComponent<P, S>{
    constructor(props: any) {
        super(props);
        console.log('这是BaseComponent')
    }

    /**
     * 重写setState方法
     * @param state
     * @param callback
     */
    setState<K extends keyof S>(
        state: ((prevState: Readonly<S>, props: Readonly<P>) => (Pick<S, K> | S | null)) | Pick<S, K> | S | null, callback?: () => void) {
        super.setState(state, callback);
    }

    componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
        console.log('错误信息==', this.constructor.name, '=组件出错:', error, errorInfo);
        // 你同样可以将错误日志上报给服务器
        return false;
    }

}

export default BaseComponent;